/*********************************************************************************************************
*
* File                : 24c02.h
* Hardware Environment: 
* Build Environment   : RealView MDK-ARM  Version: 4.20
* Version             : V1.0
* By                  : 
*
*                                  (c) Copyright 2005-2011, WaveShare
*                                       http://www.waveshare.net
*                                          All Rights Reserved
*
*********************************************************************************************************/

#ifndef __24C02_H
#define __24C02_H

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"
					  
/* Private define ------------------------------------------------------------*/
#define AT24C01A
//#define AT24C01

#define ADDR_24LC02		0xA0
#define I2C_PAGESIZE	4

#define FRAM_PAGE0 0
#define FRAM_PAGE1 1
#define FRAM_PAGE2 2
#define FRAM_PAGE3 3
#define FRAM_PAGE4 4
#define FRAM_PAGE5 5
#define FRAM_PAGE6 6
#define FRAM_PAGE7 7

/**
 * @brief Definition for connected to I2C3
 */
#define Open_I2C3                        	I2C3
#define Open_I2C3_CLK                    	RCC_APB1Periph_I2C3

#define Open_I2C3_SDA_PIN                 	GPIO_Pin_9
#define Open_I2C3_SDA_GPIO_PORT           	GPIOC
#define Open_I2C3_SDA_GPIO_CLK            	RCC_AHB1Periph_GPIOC
#define Open_I2C3_SDA_SOURCE              	GPIO_PinSource9
#define Open_I2C3_SDA_AF                  	GPIO_AF_I2C3

#define Open_I2C3_SCL_PIN                 	GPIO_Pin_7
#define Open_I2C3_SCL_GPIO_PORT           	GPIOH
#define Open_I2C3_SCL_GPIO_CLK            	RCC_AHB1Periph_GPIOH
#define Open_I2C3_SCL_SOURCE              	GPIO_PinSource7
#define Open_I2C3_SCL_AF                  	GPIO_AF_I2C3

#define I2C3_SPEED                          100000
#define I2C3_SLAVE_ADDRESS                  0xA0

/* Maximum Timeout values for flags and events waiting loops. These timeouts are
   not based on accurate values, they just guarantee that the application will 
   not remain stuck if the I2C communication is corrupted.
   You may modify these timeout values depending on CPU frequency and application
   conditions (interrupts routines ...). */   
#define I2C_Open_FLAG_TIMEOUT         ((uint32_t)0x1000)
#define I2C_Open_LONG_TIMEOUT         ((uint32_t)(10 * I2C_Open_FLAG_TIMEOUT))

void I2C3_Configuration(void);
uint8_t I2C_Read(I2C_TypeDef *I2Cx,
                 uint8_t I2C_Addr,
                 uint8_t addr,
                 uint8_t *buf,
                 uint16_t num);
uint8_t I2C_Write(I2C_TypeDef *I2Cx,
                  uint8_t I2C_Addr,
                  uint8_t addr,
                  uint8_t *buf,
                  uint16_t num);
#endif 
